(function() {
    const socket = new WebSocket('ws://' + location.hostname+ ':8080');
    socket.onopen = function(event) {
        socket.send('Hello, Server!');
    };

    socket.onmessage = function(event) {
        let msg = event.data
        console.log(msg)
        if (msg == 'fresh') {
            location.reload()
        }
    };

    socket.onerror = function(error) {
        console.error('WebSocket Error: ', error);
    };

    socket.onclose = function(event) {
        if (event.wasClean) {
            console.log('Connection closed cleanly, code=' + event.code + ' reason=' + event.reason);
        } else {
            console.error('Connection died');
        }
    };
})();

